const app = getApp()
Component({
  options: {
    addGlobalClass: true,
  },
  data: {
    achievements: 0,
    touchStartX: 0,//触摸时的原点 
    touchStartY: 0,//触摸时的原点 
    time: 0,// 时间记录，用于滑动时且时间小于1s则执行左右滑动 
    interval: "",// 记录/清理时间记录 
    touchMoveX: 0, // x轴方向移动的距离
    touchMoveY: 0, // y轴方向移动的距离
    cardCur: 0,
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg'
    }, {
      id: 1,
        type: 'image',
        url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84001.jpg',
    }, {
      id: 2,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big39000.jpg'
    }, {
      id: 3,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg'
    }, {
      id: 4,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big25011.jpg'
    }, {
      id: 5,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big21016.jpg'
    }, {
      id: 6,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big99008.jpg'
    }],
  },
  // 触摸开始事件 
  methods: {
    // cardSwiper
    cardSwiper(e) {
      this.setData({
        cardCur: e.detail.current
      })
    },
    touchStart: function (e) {
      console.log("start")
      this.touchStartX = e.touches[0].pageX; // 获取触摸时的原点 
      this.touchStartY = e.touches[0].pageY; // 获取触摸时的原点 
      // 使用js计时器记录时间 
      this.interval = setInterval(function () {
        this.time++;
      }, 100);
    },
    // 触摸移动事件 
    touchMove: function (e) {
      this.touchMoveX = e.touches[0].pageX;
      this.touchMoveY = e.touches[0].pageY;
    },
    // 触摸结束事件 
    touchEnd: function (e) {
      var moveX = this.touchMoveX - this.touchStartX
      var moveY = this.touchMoveY - this.touchStartY
      if (Math.sign(moveX) == -1) {
        moveX = moveX * -1
      }
      if (Math.sign(moveY) == -1) {
        moveY = moveY * -1
      }
      if (moveX <= moveY) {// 上下
        // 向上滑动
        if (this.touchMoveY - this.touchStartY <= -30 && this.time < 10) {
          console.log("向上滑动")
        }
        // 向下滑动 
        if (this.touchMoveY - this.touchStartY >= 30 && this.time < 10) {
          console.log('向下滑动 ');
        }
    } else {// 左右
      // 向左滑动
      if (this.touchMoveX - this.touchStartX <= -30 && this.time < 10) {
        console.log("左滑页面")
      }
      // 向右滑动 
      if (this.touchMoveX - this.touchStartX >= 30 && this.time < 10) {
        console.log('向右滑动');
        this.setData({
          achievements: 1
        })
        
        
      }
    }
    clearInterval(this.interval); // 清除setInterval 
      this.time = 0;
    },
    //跳转事件
    jump: function(e) {
      switch(e.currentTarget.dataset.src) {
        case 1:{
          console.log("1")
          wx.reLaunch({
            url: './beijing/beijing',
          })
          
        }
      }
    }
  }
  
})